package com.daJiao.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.daJiao.entity.SysSubscribeUser;
import com.daJiao.mapper.SysSubscribeUserMapper;
import com.daJiao.service.SysSubscribeUserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;


/**
 * <p>Title:      SysSubscribeUserServiceImpl. </p>
 * <p>Description 关注的用户信息表 </p>
 * <p>Copyright: Copyright (c) 2016</p>
 * <p>Company:    医百科技有限公司 </p>
 *
 * @author         yangwensheng@100doc.com.cn
 * @since      2021-03-03 11:36:07
 */
@Service
public class SysSubscribeUserServiceImpl extends ServiceImpl<SysSubscribeUserMapper,SysSubscribeUser> implements SysSubscribeUserService {

    @Resource
    private SysSubscribeUserMapper sysSubscribeUserMapper;


    @Override
    public List<SysSubscribeUser> listPage(SysSubscribeUser sysSubscribeUser){
        return sysSubscribeUserMapper.selectList(new QueryWrapper<>(sysSubscribeUser));
    }


    @Override
    public int saveSubscribeUser(SysSubscribeUser sysSubscribeUser) {
        return sysSubscribeUserMapper.saveSubscribeUser(sysSubscribeUser);
    }

    @Override
    public int deleteByOpenId(String openId) {
        return sysSubscribeUserMapper.deleteByOpenId(openId);
    }

    @Override
    public SysSubscribeUser selectByOpenId(String openId) {
        return sysSubscribeUserMapper.selectByOpenId(openId);
    }

    @Override
    public int saveSubscribeUserSample(String openId) {
        SysSubscribeUser subscribeUser = sysSubscribeUserMapper.selectByOpenId(openId);
        if(subscribeUser == null){
            SysSubscribeUser sysSubscribeUser = new SysSubscribeUser();
            sysSubscribeUser.setOpenId(openId);
            sysSubscribeUser.setNickName(openId);
            return sysSubscribeUserMapper.saveSubscribeUserSample(sysSubscribeUser);
        }
        return 0;
    }

}
